package com.groupbuying.cheetah.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 敏感信息脱敏工具
 * author cuich
 * date 2019/12/6 10:26 上午
 */
public class DesensitizationUtils {

    /**
     * 手机号脱敏
     * author cuich
     * date 2019/12/6 10:26 上午
     */
    public static String desensitizePhoneNumber(String phone) {
        Pattern p = Pattern.compile("^((13[0-9])|(14[579])|(15([0-3,5-9]))|(16[6])|(17[0135678])|(18[0-9]|19[89]))\\d{8}$");
        Matcher m = p.matcher(phone);
        if(!m.matches()){
            return null;
        }else{
            String phoneNumber = phone.substring(0, 3) + "****" + phone.substring(7, phone.length());
            return phoneNumber;
        }
    }

}
